package com.yf.cl;

public class ObtainClassLoaderTest {
    public static void main(String[] args) {
        try {
            // 获取ClassLoader的几种方法：
            // 方法一：通过反射（字节码文件）获取ClassLoader
            ClassLoader classLoader1 = Class.forName("com.yf.cl.ObtainClassLoaderTest").getClassLoader();
            System.out.println(classLoader1);

            // 方法二：通过当前线程获取ClassLoader
            ClassLoader classLoader2 = Thread.currentThread().getContextClassLoader();
            System.out.println(classLoader2);

            // 方法三：通过ClassLoader的getSystemClassLoader()方法获取
            ClassLoader classLoader3 = ClassLoader.getSystemClassLoader();
            System.out.println(classLoader3);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
